﻿using System;
using ThangNM_LIB.FUNC;

namespace ThangNM.UserControl
{
    public partial class ToolBarUC : System.Web.UI.UserControl
    {
        #region "Properties & Event"
        public delegate void CustomerEventHandler(object sender, CustomerEventArgs args);
        public event CustomerEventHandler EventButtonToolBar;
        public event CustomerEventHandler EventSelectChange;

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void ViewGroupButtonByFunction(Int16 iFuncType)
        {
            switch (iFuncType)
            {
                case ConstEx.funcButtonToolBar.LIST:
                    pnlToolBar4List.Visible = true;
                    pnlToolBar4Detail.Visible = false;
                    break;
                case ConstEx.funcButtonToolBar.DETAIL:
                    pnlToolBar4List.Visible = false;
                    pnlToolBar4Detail.Visible = true;
                    break;
                case ConstEx.funcButtonToolBar.OTHER:
                    pnlToolBar4List.Visible = false;
                    pnlToolBar4Detail.Visible = true;
                    btnInsertItem.Visible = false;
                    btnDeleteItem.Visible = false;
                    btnResetForm.Visible = false;
                    break;
            }
        }

        public void ViewButtonByFunction(Int16 iFuncType)
        {
            btnInsertItem.Visible = false;
            btnUpdateItem.Visible = false;
            btnDeleteItem.Visible = false;
            btnResetForm.Visible = false;
            btnPreview.Visible = false;

            switch (iFuncType)
            {
                case ConstEx.FunctionType.Insert:
                    btnInsertItem.Visible = true;
                    btnResetForm.Visible = true;
                    break;
                case ConstEx.FunctionType.View:
                    btnUpdateItem.Visible = true;
                    btnDeleteItem.Visible = true;
                    break;
                case ConstEx.FunctionType.Update:
                    btnUpdateItem.Visible = true;
                    break;
            }
        }

        protected void btnRefreshList_Click(object sender, EventArgs e)
        {
            if (EventButtonToolBar != null)
                EventButtonToolBar(this, new CustomerEventArgs(ConstEx.funcButtonToolBar.REFRESH_LIST, "", null));
        }

        protected void btnInsert_Click(object sender, EventArgs e)
        {
            if (EventButtonToolBar != null)
                EventButtonToolBar(this, new CustomerEventArgs(ConstEx.funcButtonToolBar.INSERT_LIST, "", null));
        }

        protected void btnDeleteList_Click(object sender, EventArgs e)
        {
            if (EventButtonToolBar != null)
                EventButtonToolBar(this, new CustomerEventArgs(ConstEx.funcButtonToolBar.DELETE_LIST, "", null));
        }

        protected void btnExportExcel_Click(object sender, EventArgs e)
        {
            if (EventButtonToolBar != null)
                EventButtonToolBar(this, new CustomerEventArgs(ConstEx.funcButtonToolBar.EXPORT_EXCEL, "", null));
        }

        protected void btnInsertItem_Click(object sender, EventArgs e)
        {
            if (EventButtonToolBar != null)
                EventButtonToolBar(this, new CustomerEventArgs(ConstEx.funcButtonToolBar.INSERT_ITEM, "", null));
        }

        protected void btnUpdateItem_Click(object sender, EventArgs e)
        {
            if (EventButtonToolBar != null)
                EventButtonToolBar(this, new CustomerEventArgs(ConstEx.funcButtonToolBar.UPDATE_ITEM, "", null));
        }

        protected void btnDeleteItem_Click(object sender, EventArgs e)
        {
            if (EventButtonToolBar != null)
                EventButtonToolBar(this, new CustomerEventArgs(ConstEx.funcButtonToolBar.DELETE_ITEM, "", null));
        }

        protected void btnResetForm_Click(object sender, EventArgs e)
        {
            if (EventButtonToolBar != null)
            {
                EventButtonToolBar(this, new CustomerEventArgs(ConstEx.funcButtonToolBar.RESET_FORM, "", null));
            }
        }

        protected void btnPreview_Click(object sender, EventArgs e)
        {
            if (EventButtonToolBar != null)
                EventButtonToolBar(this, new CustomerEventArgs(ConstEx.funcButtonToolBar.PREVIEW_TOPIC, "", null));
        }

        protected void lbtnBack_Click(object sender, EventArgs e)
        {
            if (EventButtonToolBar != null)
                EventButtonToolBar(this, new CustomerEventArgs(ConstEx.funcButtonToolBar.BACK_LIST, "", null));
        }

        public void BindData_DropDownList(object lst)
        {
            //System.Collections.SortedList sList, System.Data.DataTable dtList, 
            ddlStatus.DataSource = lst;
            ddlStatus.DataTextField = "Value";
            ddlStatus.DataValueField = "Key";
            ddlStatus.DataBind();
        }

        public void SetDefaultValue(object value)
        {
            ddlStatus.SelectedValue = Convert.ToString(value);
        }

        protected void ddlStatus_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (EventSelectChange != null)
                EventSelectChange(this, new CustomerEventArgs(0, ddlStatus.SelectedValue, null));
        }
    }
}